package pt.nmfa.peste.scrappers.file;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class LircConfigScrapper extends FileScrapper {

	private String name;
	private List<String> codeList;

	public LircConfigScrapper(String file) {
		super(file);
	}

	protected void update() {
		boolean isRawCode=contains("raw_codes");
		if(!isRawCode)
		{
			name = getValueAsString("name (.+?) ");
			if(name!=null)
				name=name.trim();
			String codes=getValueAsString("codes(.+?)codes");
			StringTokenizer st=new StringTokenizer(codes," ");
			if(st.hasMoreTokens())
				codeList=new ArrayList<String>();
			while(st.hasMoreTokens()){
				codeList.add(st.nextToken());
				if(st.hasMoreTokens())
					st.nextToken();
			}
		}else
		{
			List<String> list=getValueAsList("name (.+?) ");
			name=list.get(0);
			System.out.println(name);
			list.remove(0);
			codeList=list;
		}
	}

	public List<String> getCodeList() {
		return codeList;
	}

	public String getName() {
		return name;
	}

}
